#include "mainscene.h"
#include "ui_mainscene.h"
#include <QPainter>
#include "mypushbutton.h"
#include <QTimer>
//#include <QMediaPlayer>
MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);
    setFixedSize(320, 588);
    setWindowIcon(QIcon(":/myres/Coin0001.png"));
    setWindowTitle("coinFlip");
    connect(ui->actionquit, &QAction::triggered, [=](){

        close();
    });
    //开始按钮

    MyPushButton* mypushbtn = new MyPushButton(":/myres/MenuSceneStartButton.png");
    mypushbtn->setParent(this);
    mypushbtn->move(this->width() * 0.5 - mypushbtn->width() * 0.5, this->height() * 0.7);

    chooseL = new ChooseLevel;
    connect(chooseL, &ChooseLevel::returnToMain, [=](){
        QTimer::singleShot(200, this, [=](){
            this->setGeometry(chooseL->geometry());
            chooseL->close();
            this->show();
        });//延时

    });
    connect(mypushbtn, &QPushButton::clicked, [=](){
        mypushbtn->zoom();
        QTimer::singleShot(300, this, [=](){
            chooseL->setGeometry(this->geometry());
            this->hide();
            chooseL->show();
        });//延时
    });




}

void MainScene::paintEvent(QPaintEvent* ev)
{
    QPainter mypainter(this);
    QPixmap pixmap;
    pixmap.load(":/myres/PlayLevelSceneBg.png");//装载图片
    mypainter.drawPixmap(0, 0, this->width(), this->height(), pixmap);

    pixmap.load(":/myres/Title.png");
    pixmap = pixmap.scaled(pixmap.width() * 0.5, pixmap.height() * 0.5);//缩放pixmap
    mypainter.drawPixmap(10, 30, pixmap);//添加背景图

}
MainScene::~MainScene()
{
    delete ui;
}
